/*
 * fileDataHandle.h
 *
 * Created on: Feb 2017
 * 		Author : macro gu
 *	email & skype : macrogu@qq.com
 *	
 */


#pragma once

#include <set>
#include <thread>

#include "epoll_socket.h"
#include "log.h"
#include "singleton.h"
#include "opFastdfs.h"
#include "message.h"





class CFileDataHandle : public ISingleton<CFileDataHandle> 
{

	public:

		// if has this client  true: has  false: not have
		bool HasThisClients(const EpollContext* const epoll_context); 

		// insert a client
		void InsertNewClient(const int& clientfd);
		// clear all clients
		void ClearAllClients();
		// delete a client
		void DeleteOneClient(const int& clientfd);

		// insert a client data
		void InsertClientFastdfsData(const int& clientfd, const std::shared_ptr<SFastdfsData>& clientData);
		// get a client fastdfs data
		std::shared_ptr<SFastdfsData> GetClientData(const int& clientfd);
		// delete a client fastdfs data
		void DeleteOneClientFastdfsData(const int& clientfd);
		// clear all clients fastdfs data
		void ClearAllClientsFastdfsData();

	private:

		// store all legal clients fd
		std::set<int> m_AllLegalClients;
		// key: client connected fd , value will put to fastdfs data
		std::map<int, std::shared_ptr<SFastdfsData>> m_AllClientFastDFSData;

		friend ISingleton<CFileDataHandle>;
		friend class std::auto_ptr<CFileDataHandle>;

		CFileDataHandle();
		~CFileDataHandle();

};
